using System;
using System.Web;
using Sedna.Core.Common;

namespace Sedna.Core.Controller.Common
{
	/// <summary>
	/// takes a parameter value from HttpRequest (regardless UrlString or Post)
	/// and returns it.
	/// It looks up a parameter in HttpContext under the RequestName property value
	/// </summary>
	public class HttpRequest2ExecutionContextActionParam : IActionParam
	{
		private string name;
		private string requestName;

		/// <summary>
		/// the name that is used to set up the parameter value into the ExecutionContext
		/// </summary>
		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		/// <summary>
		/// parameter name in the Request
		/// </summary>
		public string RequestName
		{
			set { requestName = value; }
		}

		/// <summary>
		/// retrieves a value of the parameter from the HttpRequest
		/// </summary>
		/// <param name="executionContext">is not used</param>
		/// <returns>a value of the parameter from the Request or null if no such parameter is found</returns>
		public string GetValue(IExecutionContext executionContext)
		{
			return (string)executionContext.GetScopedValue(requestName, Scope.Request);
		}
	}
}
